let id =1
template.defaults.imports.dateFormat = function (dtStr) {
  let date = new Date(dtStr)
  let y = date.getFullYear()
  let m = date.getMonth() + 1
  let d = date.getDate()
 
  return y + '-' + m + '-' + d 
}
function comment() {
  $.ajax({
    url:`http://localhost:8888/api/articles/${id}/comments`,
    success:function(res){
     let tem = template('tpl-comment',res)
     $('#mycomment').html(tem)
    }
  })
}
comment()

// 提交评论
$('form').on('submit',function (e) {
  e.preventDefault()
  
  let content = $(this).serialize().substring(8)
  console.log(content)
  $.ajax({
    type:'post',
    url:`http://localhost:8888/api/articles/${id}/comments`,
    data:{
      uname:'whk',
      content:content
    },
    success:function(res){
      console.log(res)
      comment() 
      $('textarea').val('')
    }
    
  })
})